/* GUI CONVERTED from rcctdela.p (converter v1.76) Tue Jun 11 06:55:45 2002 */
/* rcctdela.p - Subprogram to delete/archive unlinked container records       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.2 $                                                              */
/*                                                                            */
/* Sub-program called when sub-levels are deleted                             */
/*                                                                            */
/* $Revision: 1.2 $     BY:Manish K.        DATE:05/20/02 ECO: *P00C*            */
/*                                                                            */
/*V8:ConvertMode=Report                                                       */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i}

/* THIS IS THE CODE FOR DELETE SUBLEVELS = YES */
define input parameter i_site      like abs_site    no-undo.
define input parameter i_site1     like abs_site    no-undo.
define input parameter i_cont      like abs_id      no-undo.
define input parameter i_cont1     like abs_id      no-undo.
define input parameter i_cont_type like abs_type    no-undo.
define input parameter i_delete    like mfc_logical no-undo.
define input parameter i_filename  as   character   no-undo.

define buffer ship_line for abs_mstr.

define stream s_history.

define variable l_abs_recid as recid         no-undo.
define variable l_delproc   like mfc_logical no-undo.
define variable undotran    like mfc_logical no-undo.
define variable v_id        like abs_id      label "Number" no-undo.
define variable level       as   character   label "Level"  no-undo.

define temp-table t_abs1
   field t_abs_shipfrom like abs_shipfrom
   field t_abs_id1 like abs_id.

FORM /*GUI*/ 
   level
   v_id
   space(3)
   abs_item
   abs_type
   abs_qty  format "->,>>>,>>9.9<<<<<<<<"
   pt_um
   abs_site
   abs_loc
   abs_lotser
   abs_ref
with STREAM-IO /*GUI*/  frame b down width 132 attr-space.

/* SET  EXTERNAL LABELS */
setFrameLabels(frame b:handle).

/* FOR CONTAINER TYPES "S" OR "R" OR "U" */

if i_cont_type <>  ""  then do:
   for each ship_line where
      (ship_line.abs_shipfrom >= i_site and
       ship_line.abs_shipfrom <= i_site1 ) and
      (substring(ship_line.abs_id,2) >= i_cont and
       substring(ship_line.abs_id,2) <= i_cont1 ) and
      ship_line.abs_id begins "c"    and
      ship_line.abs_par_id = ""  and
      ship_line.abs_type = i_cont_type no-lock:

      for first pt_mstr
         fields ( pt_part pt_um )
         where pt_part = ship_line.abs_item no-lock:
      end. /* FOR FIRST */

      /* DISPLAY THE PARENT CONTAINER RECORD */
      display
         "0"                @ level
         ship_line.abs_id   @ v_id
         ship_line.abs_item @ abs_mstr.abs_item
         ship_line.abs_type @ abs_mstr.abs_type
         ship_line.abs_qty  @ abs_mstr.abs_qty
         if ship_line.abs__qad02 <> "" then
            abs__qad02
         else
            if available pt_mstr then
               pt_um
            else
               ""
          @ pt_um
         ship_line.abs_site   @ abs_mstr.abs_site
         ship_line.abs_loc    @ abs_mstr.abs_loc
         ship_line.abs_lotser @ abs_mstr.abs_lotser
         ship_line.abs_ref    @ abs_mstr.abs_ref
      with frame b STREAM-IO /*GUI*/ .
      down 1 with frame b.

      /* APPEND THE ABS_MSTR RECORD TO THE STREAM */
      if i_filename <> ""  then do:
         output stream s_history to value (i_filename) append.
         export stream s_history "abs_mstr".
         export stream s_history ship_line.
         output stream s_history close.
      end.  /* IF I_FILENAME <> ""  */
      l_abs_recid = recid(ship_line).

      /* INTERNAL PROCEDURE CALLED TO DISPLAY CHILD RECORDS */
      run p_disp ( input 0,
                   input abs_id ,
                   input abs_shipfrom).

      if i_delete then do:
         /* DELETE THE CHILD RECORDS */
         {gprun.i ""rcctwbu1.p"" "(l_abs_recid,
                                   input no ,
                                   input yes ,
                                   input l_delproc,
                                   output undotran)" }

         create t_abs1.
         assign
            t_abs_shipfrom = ship_line.abs_shipfrom
            t_abs_id1      = ship_line.abs_id.

         /* INTERNAL PROCEDURE FOR DELETION OF UNLINKED PARENT CONTAINER */
         run p_delete.
      end. /* IF I_DELETE */

      put skip(1).
  end.  /* FOR EACH SHIP_LINE */

end. /* IF I_cont_type <> "" */

if i_cont_type =  ""  then
do:
   for each ship_line where
      (ship_line.abs_shipfrom >= i_site and
       ship_line.abs_shipfrom <= i_site1 ) and
      (substring(ship_line.abs_id,2) >= i_cont and
       substring(ship_line.abs_id,2) <= i_cont1 ) and
      ship_line.abs_id begins "c"    and
      ship_line.abs_par_id = ""  no-lock:

      for first pt_mstr
         fields ( pt_part pt_um )
         where pt_part = ship_line.abs_item no-lock:
      end. /* FOR FIRST */

      display
         fill (".", 0) + if ship_line.abs_id begins "I" then "I"
                         else ship_line.abs_id @ v_id
         ship_line.abs_item @ abs_mstr.abs_item
         ship_line.abs_type @ abs_mstr.abs_type
         ship_line.abs_qty  @ abs_mstr.abs_qty
         if ship_line.abs__qad02 <> ""  then
            abs__qad02
         else
            if available pt_mstr then
               pt_um
            else
               ""
         @ pt_um
         ship_line.abs_site   @ abs_mstr.abs_site
         ship_line.abs_loc    @ abs_mstr.abs_loc
         ship_line.abs_lotser @ abs_mstr.abs_lotser
         ship_line.abs_ref    @ abs_mstr.abs_ref
     with frame b STREAM-IO /*GUI*/ .
     down 1 with frame b.

     if i_filename <> ""  then do:
        output stream s_history to value (i_filename) append.
        export stream s_history "abs_mstr".
        export stream s_history ship_line.
        output stream s_history close.
     end.  /* IF I_FILENAME <> "" */

     l_abs_recid = recid(ship_line).

     run p_disp ( input 0, input abs_id , input abs_shipfrom).
     if i_delete then do:
        {gprun.i ""rcctwbu1.p"" "(input l_abs_recid,
                                  input no ,
                                  input yes ,
                                  input l_delproc,
                                  output undotran)" }

        create t_abs1.
        assign
           t_abs_shipfrom = ship_line.abs_shipfrom
           t_abs_id1 = ship_line.abs_id.
        run p_delete.
     end. /* IF I_DELETE */

     put skip(1).
  end.  /* FOR EACH SHIP_LINE */

end. /* IF I_CONT_TYPE = "" */

PROCEDURE p_disp:
   define input parameter i_indent as integer  no-undo.
   define input parameter l_abs_id like abs_id no-undo.
   define input parameter l_abs_shipfrom like abs_shipfrom no-undo.

   i_indent = i_indent + 1.
   for each abs_mstr where abs_shipfrom = l_abs_shipfrom
                       and abs_id begins "i"
                       and abs_par_id = l_abs_id no-lock:
      for first pt_mstr
         fields ( pt_part pt_um )
         where pt_part = abs_mstr.abs_item no-lock:
      end. /* FOR FIRST */

      display
         fill ( "." , i_indent) + string(i_indent) @ level
         fill (".", i_indent) + "I"  @ v_id
         abs_item
         abs_type
         abs_qty
         if abs__qad02 <> "" then
            abs__qad02
         else
            if available pt_mstr then
               pt_um
            else
               ""
         @ pt_um
         abs_site
         abs_loc
         abs_lotser
         abs_ref
      with frame b STREAM-IO /*GUI*/ .
      down 1 with frame b.

      if i_filename <> ""  then do:
         output stream s_history to value (i_filename) append.
         export stream s_history "abs_mstr".
         export stream s_history abs_mstr.
         output stream s_history close.
      end.  /* IF I_FILENAME <> "" */

   end.

   for each abs_mstr where abs_shipfrom = l_abs_shipfrom
                       and abs_par_id = l_abs_id
                       and abs_id begins "c" no-lock:

      for first pt_mstr
         fields ( pt_part pt_um )
         where pt_part = abs_mstr.abs_item no-lock:
      end. /* FOR FIRST */

      display
         fill ( "." , i_indent) + string(i_indent) @ level
         fill (".", i_indent) + abs_id @ v_id
         abs_item
         abs_type
         abs_qty
         if abs__qad02 <> ""  then
            abs__qad02
         else
            if available pt_mstr then
               pt_um
            else
               ""
          @ pt_um
         abs_site
         abs_loc
         abs_lotser
         abs_ref
      with frame b STREAM-IO /*GUI*/ .
      down 1 with frame b.

      if i_filename <> ""  then do:
         output stream s_history to value (i_filename) append.
         export stream s_history "abs_mstr".
         export stream s_history abs_mstr.
         output stream s_history close.
      end.  /* IF I_FILENAME */

      run p_disp (input i_indent, input abs_id , input abs_shipfrom).

   end. /* FOR EACH ABS_MSTR */

END PROCEDURE. /* PROCEDURE P_DISP */


PROCEDURE p_delete:

   for each t_abs1:
      find abs_mstr where abs_shipfrom  = t_abs_shipfrom
                     and  abs_id        = t_abs_id1
                     exclusive-lock no-error.
      if available abs_mstr then do:
        delete abs_mstr.
      end.

   end. /* FOR EACH T_ABS1 */

END PROCEDURE.  /* PROCEDURE P_DELETE */
